Skip to content

Styler-ify more Credo rules: FilterReject, RejectFilter, MapMap, and and !is_* guards#15

Merged
JesseHerrick merged 4 commits into
mainfrom
more-sensible-rules
May 7, 2026
Merged

Styler-ify more Credo rules: FilterReject, RejectFilter, MapMap, and and !is_* guards#15
JesseHerrick merged 4 commits into
mainfrom
more-sensible-rules

Conversation

@JesseHerrick
Copy link
Copy Markdown
Member

@JesseHerrick JesseHerrick commented May 7, 2026

Styler-ify more Credo rules: FilterReject, RejectFilter, MapMap, and !is_* guards

Adds pipe-collapsing for:

  • Enum.filter |> Enum.reject (and the reverse)
  • Enum.map |> Enum.map, and rewrites !is_nil/is_*/etc. to use not.
  • Also extends the empty-check rewrite to cover String.length.

Note

Medium Risk
Medium risk because it expands non-trivial AST transformations (inlining/collapsing Enum.map chains and predicate merging), which could subtly change output code shape or edge-case semantics if pattern guards miss cases.

Overview
Adds new pipe-collapsing rewrites in Styler.Style.Pipes for Enum.filter |> Enum.reject and Enum.reject |> Enum.filter, plus a new Enum.map |> Enum.map merge that inlines captures/1-arity lambdas into a single Enum.map with a piped body (with safeguards to skip unsafe inlining/variable-shadowing cases).

Enhances predicate combination to support optional negation, and introduces helper logic for capture/lambda inlining and pipifying nested calls.

Updates Styler.Style.SingleNode to rewrite !is_* guard-style predicates to not is_*, and extends the “expensive empty check” rewrite to handle String.length(x) <op> 0|1 via comparisons against "". Documentation and tests are updated to reflect the newly covered Credo rules and behaviors.

Reviewed by Cursor Bugbot for commit 33551cc. Bugbot is set up for automated code reviews on this repo. Configure here.

…!is_* guards

Adds pipe-collapsing for Enum.filter |> Enum.reject (and the reverse),
Enum.map |> Enum.map, and rewrites !is_nil/is_*/etc. to use `not`.
Also extends the empty-check rewrite to cover String.length and byte_size.
Comment thread lib/style/pipes.ex
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f20b7ba. Configure here.

Comment thread lib/style/pipes.ex Outdated
byte_size(x) > 0 and x != "" are equivalent and equally efficient
on binaries (byte_size reads the size header in O(1), and binary
inequality short-circuits on that same header). Neither form is more
idiomatic than the other, so there's no clear win to rewriting one to
the other. Keep the String.length rewrite, which is a real perf win.
Reported by Cursor Bugbot: the comment on iteration_var_name said
"if either side is an inline fn x -> ...", but the function only
inspected f1. When f1 was a capture (e.g. &Mod.foo/1) and f2 was
fn descriptive_name -> ..., the merged lambda defaulted to :arg1
instead of using f2's more meaningful name.
@JesseHerrick JesseHerrick merged commit c723fca into main May 7, 2026
11 checks passed
@JesseHerrick JesseHerrick deleted the more-sensible-rules branch May 7, 2026 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant